<!--
 * @Author: Seon.Hu SeonHu@126.com
 * @Date: 2023-06-16 15:13:39
 * @LastEditors: Seon.Hu SeonHu@126.com
 * @LastEditTime: 2023-11-27 17:32:04
 * @FilePath: \bg-vben\src\views\system\report\index.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <PageWrapper title="打印示例">
    <CollapseContainer title="json打印表格">
      <a-button type="primary" @click="jsonPrint">打印</a-button>
    </CollapseContainer>
    <CollapseContainer title="打印FastReport">
      <a-button type="primary" @click="fastreportPrint">打印</a-button>
    </CollapseContainer>

    <a-button type="primary" class="mt-5" @click="imagePrint">Image Print</a-button>
  </PageWrapper>
</template>

<script lang="ts">
  import { defineComponent } from 'vue';
  import { PageWrapper } from '@/components/Page';
  import { CollapseContainer } from '@/components/Container/index';

  import printJS from 'print-js';

  export default defineComponent({
    name: 'PrintDemo',
    components: { PageWrapper, CollapseContainer },
    setup() {
      function jsonPrint() {
        printJS({
          printable: [
            { name: 'll', email: '123@gmail.com', phone: '123' },
            { name: 'qq', email: '456@gmail.com', phone: '456' },
          ],
          properties: ['name', 'email', 'phone'],
          type: 'json',
        });
      }

      async function fastreportPrint() {
        // const base64str = await getReport();
        // console.log('1111', base64str);
        // printJS({
        //   printable: base64str,
        //   type: 'pdf',
        //   base64: true,
        // });
      }

      function imagePrint() {
        printJS({
          printable: [
            'https://anncwb.github.io/anncwb/images/preview1.png',
            'https://anncwb.github.io/anncwb/images/preview2.png',
          ],
          type: 'image',
          header: 'Multiple Images',
          imageStyle: 'width:100%;',
        });
      }
      return {
        jsonPrint,
        fastreportPrint,
        imagePrint,
      };
    },
  });
</script>
